#include "dicom/ref_object.h"

#include <gwbase/base/atomic.h>
#include <gwbase/base/logging.h>

namespace dicom {

static AtomicInt64 g_obj_id(0);

RefObject::RefObject(int obj_type)
    : refs_(0), obj_type_(obj_type), obj_id_(g_obj_id.Increment()) {}

RefObject::~RefObject() {}

void RefObject::Unref() {
  LOG_TRACE << "RefObject::Unref(): " << this;
  if (refs_.Decrement() == 0) {
    LOG_TRACE << "Destroy RefObject: " << this;
    delete this;
  }
}

void RefObject::AddRef() {
  LOG_TRACE << "RefObject::AddRef(): " << this;
  refs_.Increment();
}
}
